package com.remon.quartz.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.List;

/**
 * 分页处理类
 *
 * @author remon
 * @create 2018-09-04 17:53
 **/
@Data

public class PageRes<T> implements Serializable {

    /**
     * 总条数
     */
    private Long totalElements;

    /**
     * 总页数
     */
    private Integer totalPages;

    /**
     * 当前页
     */
    private Integer pageNo;

    /**
     * 每页条数
     */
    private Integer pageSize;

    /**
     * 再 elements 的位置
     */
    private int numberOfElements;

    /**
     * 内容
     */
    private List<T> content;

    /**
     * 当前页是否有数据
     */
    private boolean hasContent;

    /**
     * 是否为第一页
     */
    private boolean first;

    /**
     * 是否为最后一页
     */
    private boolean last;

    /**
     * 是否有下一页
     */
    private boolean next;

    /**
     * 是否有上一页
     */
    private boolean previous;

    @JsonIgnore
    private Page<T> page;

    public PageRes(Page<T> page) {
        this.page = page;
        this.first = page.isFirst();
        this.next = page.hasNext();
        this.previous = page.hasPrevious();
        this.content = page.getContent();
        this.numberOfElements = page.getNumberOfElements();
        this.hasContent = page.hasContent();
        this.pageNo = page.getNumber();
        this.pageSize = page.getSize();
        this.totalElements = page.getTotalElements();
        this.totalPages = page.getTotalPages();
    }


}
